#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
double POW_MOD(int a, int k) {
	LL p=16;
	LL res=1;
	while (a) {
		if (a&1) {
			res=(res*p)%k;
		}
		p=(p*p)%k;
		a=a>>1;
	}
	double ret=(double)(res)/(double)(k);
	return ret;
}
int solve(int ask) {
	double res=0;
	ask=ask-1;
	for (int i=0; i<=ask; ++i) {
		double k=ask-i;
		res=res+4*POW_MOD(i, 8*k+1)-2*POW_MOD(i, 8*k+4)-POW_MOD(i, 8*k+5)-POW_MOD(i, 8*k+6);
		if (res<0) res+=1;
	}
	res=res*16;
	LL ret=res;
	ret=ret%16;
	return ret;
}
char HEX[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
int main() {
	int T;
	cin>>T;
	int ask;
	for (int cas=1; cas<=T; ++cas) {
		cin>>ask;
		int ans=solve(ask);
		printf("Case #%d: %d %c\n", cas, ask, HEX[ans]);
	}
	return 0;
}
